package com.sunrin.applepie.gm_player.activity;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.provider.MediaStore;
import android.widget.ArrayAdapter;
import android.app.Activity;
import android.app.ListActivity;
import android.database.Cursor;

public class Tab_ListActivity extends ListActivity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		List<String> musiclists = getMusicLists();
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, musiclists);
		setListAdapter(adapter);
	}

	public List<String> getMusicLists() {
		List<String> list = new ArrayList<String>();
		String[] cursorColumns = new String[] { MediaStore.Audio.Playlists._ID,
				MediaStore.Audio.Playlists.NAME };
		Cursor cursor = (Cursor) getContentResolver().query(
				MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, cursorColumns,
				null, null, null);

		if (cursor == null) {
			return list;
		}
		if (cursor.moveToFirst()) {
			int idColumn = cursor
					.getColumnIndex(MediaStore.Audio.Playlists._ID);
			int musiclistColumn = cursor
					.getColumnIndex(MediaStore.Audio.Playlists.NAME);
			do {
				String musiclist = cursor.getString(musiclistColumn);
				list.add(musiclist);
			} while (cursor.moveToNext());
		}
		cursor.close();
		return list;
	}
}
